﻿<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars2d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon/favicon.ico" />

    <meta name="keywords" content="火星科技,leaflet,mars2d,GIS,marsgis,二维,地图,地球,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 leaflet leaflet开发 leaflet框架 二维 地图 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 二维地图 全景漫游 地理信息系统 云GIS 二维GIS GIS平台 WebGIS"
    />

    <title>军事标绘 |二维地图| 火星科技|合肥火星科技|合肥火星科技有限公</title>
    <script
      type="text/javascript"
      src="/lib/include-lib.js"
      libpath="/lib/"
      include="jquery,font-awesome,bootstrap,bootstrap-checkbox,layer,terraformer,haoutil,turf,mars2d,mars2d-widget"
    ></script>

    <!-- KML/KMZ 转 GeoJSON 格式 -->
    <script type="text/javascript" src="../lib/kml/kml-geojson.js"></script>

    <link href="/css/style.css" rel="stylesheet" />
  </head>

  <body>
    <div id="mars2dContainer" class="mars2d-container"></div>
    <div class="infoview infoview-left">
      <div>
        图层状态：
        <div class="checkbox checkbox-primary checkbox-inline">
          <input id="chkShow" class="styled" type="checkbox" checked />
          <label for="chkShow"> 显示隐藏 </label>
        </div>
        <div class="checkbox checkbox-primary checkbox-inline">
          <input id="chkPopup" class="styled" type="checkbox" checked />
          <label for="chkPopup"> Popup绑定 </label>
        </div>
        <div class="checkbox checkbox-primary checkbox-inline">
          <input id="chkTooltip" class="styled" type="checkbox" />
          <label for="chkTooltip"> Tooltip绑定 </label>
        </div>
        <div class="checkbox checkbox-primary checkbox-inline">
          <input id="chkContextMenu" class="styled" type="checkbox" checked />
          <label for="chkContextMenu"> 右键菜单绑定 </label>
        </div>

        <div class="checkbox checkbox-primary checkbox-inline">
          <input id="chkHasEdit" class="styled" type="checkbox" checked />
          <label for="chkHasEdit"> 是否编辑 </label>
        </div>
      </div>
      <div>
        图层管理：
        <input id="btnClear" type="button" class="btn btn-danger" value="清除" />
        <input id="btnExpFile" type="button" class="btn btn-primary" value="保存GeoJSON" title="保存为GeoJSON文件" />
        <input id="btnImpFile" type="button" class="btn btn-primary" value="打开GeoJSON" title="打开之前保存的GeoJSON文件" />

        <input id="input_draw_file" type="file" accept=".json,.geojson" style="display: none" />
      </div>

      <div>
        标号：
        <input type="button" class="btn btn-primary" value="粗直箭头" onclick="drawPolygon('straightArrow')" />
        <input type="button" class="btn btn-primary" value="粗单尖直箭头" onclick="drawPolygon('fineArrow')" />
        <input type="button" class="btn btn-primary" value="燕尾直箭头" onclick="drawPolygon('fineArrowYW')" />
        <input type="button" class="btn btn-primary" value="攻击箭头" onclick="drawPolygon('attackArrow')" />
        <input type="button" class="btn btn-primary" value="平尾攻击箭头" onclick="drawPolygon('attackArrowPW')" />
        <input type="button" class="btn btn-primary" value="燕尾攻击箭头" onclick="drawPolygon('attackArrowYW')" />

        <input type="button" class="btn btn-primary" value="钳击箭头" onclick="drawPolygon('doubleArrow')" />
        <input type="button" class="btn btn-primary" value="闭合曲面" onclick="drawPolygon('closeVurve')" />
        <input type="button" class="btn btn-primary" value="集结地" onclick="drawPolygon('gatheringPlace')" />
      </div>
    </div>

    <script src="/js/common.js"></script>
    <script src="./map.js"></script>

    <script type="text/javascript">
      function initUI() {
        $("#btnClear").click(function () {
          graphicLayer.clear()
        })

        $("#chkPopup").change(function () {
          let val = $(this).is(":checked")
          if (val) {
            bindLayerPopup(graphicLayer)
          } else {
            graphicLayer.unbindPopup()
          }
        })

        //可在图层上绑定tooltip,对所有加到这个图层的矢量数据都生效
        $("#chkTooltip").change(function () {
          let val = $(this).is(":checked")

          if (val) {
            graphicLayer.bindTooltip("我是layer上绑定的Tooltip")
          } else {
            graphicLayer.unbindTooltip()
          }
        })

        $("#chkContextMenu").change(function () {
          let val = $(this).is(":checked")

          if (val) {
            bindLayerContextMenu(graphicLayer)
          } else {
            graphicLayer.unbindContextMenu(true)
          }
        })

        $("#chkHasEdit").change(function () {
          let val = $(this).is(":checked")

          graphicLayer.hasEdit = val //启用编辑
        })

        $("#chkShow").change(function () {
          let val = $(this).is(":checked")

          graphicLayer.show = val //显示隐藏
        })

        $("#btnClear").click(function () {
          graphicLayer.clear()
        })

        $("#btnExpFile").click(function () {
          if (graphicLayer.length === 0) {
            window.layer.msg("当前没有标注任何数据，无需保存！")
            return
          }

          let geojson = graphicLayer.toGeoJSON()
          haoutil.file.downloadFile("我的标注.json", JSON.stringify(geojson))
        })

        $("#btnImpFile").click(function () {
          $("#input_draw_file").click()
        })

        function clearSelectFile() {
          if (!window.addEventListener) {
            document.getElementById("input_draw_file").outerHTML += "" //IE
          } else {
            document.getElementById("input_draw_file").value = "" //FF
          }
        }

        $("#input_draw_file").change(function (e) {
          let file = this.files[0]

          let fileName = file.name
          let fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase()

          if (fileType == "json" || fileType == "geojson") {
            let reader = new FileReader()
            reader.readAsText(file, "UTF-8")
            reader.onloadend = function (e) {
              let json = this.result
              graphicLayer.loadGeoJSON(json, {
                flyTo: true
              })
              clearSelectFile()
            }
          } else {
            window.layer.msg("暂不支持 " + fileType + " 文件类型的数据！")
            clearSelectFile()
          }
        })

        //属性窗口 监听事件
        graphicLayer.on(mars2d.EventType.editStart, function (e) {
          startEditing(e.graphic)
        })
        graphicLayer.on(mars2d.EventType.editMovePoint, function (e) {
          startEditing(e.graphic)
        })
        graphicLayer.on(mars2d.EventType.editRemovePoint, function (e) {
          startEditing(e.graphic)
        })
        graphicLayer.on(mars2d.EventType.editStop, function (e) {
          stopEditing()
        })
        graphicLayer.on(mars2d.EventType.removeGraphic, function (e) {
          stopEditing()
        })
      }

      function bindLayerPopup(graphicLayer) {
        graphicLayer.bindPopup(function (event) {
          let attr = event.graphic?.attr || {}
          attr.test1 = "测试属性"
          // attr["视频"] = `<video src='http://data.mars2d.cn/file/video/lukou.mp4' controls autoplay style="width: 300px;" ></video>`;

          return mars2d.Util.getTemplateHtml({ title: "layer上绑定的Popup", template: "all", attr: attr })
        })
      }

      //附加：激活属性编辑widget【非必需，可以注释该方法内部代码】
      let timeTik

      function startEditing(graphic) {
        clearTimeout(timeTik)

        let plotAttr = mars2d.widget.getClass("widgets/plotAttr/widget.js")
        if (plotAttr && plotAttr.isActivate) {
          plotAttr.startEditing(graphic, graphic.coordinates)
        } else {
          mars2d.widget.activate({
            map: map,
            uri: "widgets/plotAttr/widget.js",
            name: "属性编辑",
            graphic: graphic,
            lonlats: graphic.coordinates
          })
        }
      }

      function stopEditing() {
        timeTik = setTimeout(function () {
          mars2d.widget.disable("widgets/plotAttr/widget.js")
        }, 200)
      }
      //附加：激活属性编辑widget【非必需，可以注释该方法内部代码】
    </script>

  </body>
</html>
